home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12734 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: chaos.kulnet.kuleuven.ac.be!usenet
  2. From: Peter.Vanovertveldt@cc.kuleuven.ac.be (PeterV)
  3. Newsgroups: comp.lang.c++
  4. Subject: polyformism
  5. Date: Thu, 21 Mar 1996 13:18:29 GMT
  6. Organization: KULeuven
  7. Message-ID: <4irl0e$qg1@chaos.kulnet.kuleuven.ac.be>
  8. NNTP-Posting-Host: ipv13006.cc.kuleuven.ac.be
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. I have the following question:
  12. How can I use call by value in a function call, when I'm using
  13. polyformism ?
  14.  
  15. class Base
  16.           (
  17.           ....
  18.           );
  19. class Deriv1: public Base
  20.           (
  21.          ....
  22.           );
  23. class Deriv2: public Base
  24.           (
  25.         .....
  26.           );
  27. main()
  28.           (
  29.           Base *pointer;
  30.           pointer=new Deriv1;
  31.           fun(pointer);
  32.           )
  33. fun(Base *p)
  34.           ( 
  35.           // I would like to edit the object at which p points at
  36. without changing the original object.
  37.           )
  38.  
  39. To declare the new operator virtual, would be a solution; but virtual
  40. operators aren't possible ! ex. Base *pbis;
  41. pbis=new (*p);  // and hope that Pbis points at a copy of the original
  42. object.
  43. Make a virtual copy function would be a solution too but I think it's
  44. a bad one. 
  45. I would like to make sure that the fun function is independent from
  46. future derived classes form the Base class, ex Deriv3.
  47.  
  48.